﻿/*****************************************
 * 
 *  copyright (c) by ylshen
 * 
 *  author : ylshen (syl.lucky@gmail.com)
 * 
 **************************************** */

using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using JYStockAnalyser.Model;

namespace JYStockAnalyser.WinUI
{
    public class StyleManager
    {
        public static void SetStyle(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;
            zgc.IsEnableZoom = false;
            myPane.Title.IsVisible = false;
            myPane.XAxis.Title.IsVisible = false;
            myPane.YAxis.Title.IsVisible = false;

            myPane.Legend.IsShowLegendSymbols = false;
            myPane.Legend.Border.IsVisible = false;
            myPane.Legend.Border.Color = Color.Transparent;
            myPane.Legend.Border.Width = 10F;
            myPane.Legend.Fill = new Fill(Color.Transparent);
            myPane.Legend.Position = LegendPos.InsideTopLeft;       
            myPane.Legend.FontSpec.Size = 24F;
            myPane.Legend.FontSpec.FontColor = Color.Yellow;

            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.XAxis.MajorGrid.IsVisible = false;
            myPane.YAxis.MajorGrid.Color = Color.FromArgb(200, 200, 200);
            myPane.YAxis.MajorGrid.DashOn = 1000F;

       
            myPane.Chart.Border.Width = 0f;

            myPane.Fill = new Fill(Color.Black);

            myPane.XAxis.Scale.FontSpec.FontColor = Color.DeepSkyBlue;
            myPane.XAxis.Scale.FontSpec.Size = 20F;
            myPane.YAxis.Scale.FontSpec.FontColor = Color.DeepSkyBlue;
            myPane.YAxis.Scale.FontSpec.Size = 20F;

            myPane.XAxis.MajorTic.Color = Color.FromArgb(200, 200, 200);
            myPane.XAxis.MinorTic.Color = Color.FromArgb(200, 200, 200);
            myPane.YAxis.MajorTic.Color = Color.FromArgb(200, 200, 200);
            myPane.YAxis.MinorTic.Color = Color.FromArgb(200, 200, 200);
           
            myPane.Chart.Fill = new Fill(Color.FromArgb(73, 106, 159), Color.FromArgb(30, 30, 30), 0.75F);

            zgc.IsShowPointValues = true;
        }

        public static Color GetSymbolColor(int index)
        {
            index = index % 10;
            switch (index)
            {
                case 0:
                    return Color.Red;
                case 1:
                    return Color.FromArgb(0xBF, 0xFF, 0xFF);
                case 2:
                    return Color.FromArgb(0xEA, 0xBF, 0xFF);
                case 3:
                    return Color.FromArgb(0xFF, 0xE6, 0xBF);
                case 4:
                    return Color.FromArgb(0xFF, 0xE6, 0xBF);
                case 5:
                    return Color.FromArgb(0xFF, 0xFF, 0xBF);
                case 6:
                    return Color.FromArgb(0xFF, 0xBF, 0xBF);
                case 7:
                    return Color.FromArgb(0xbf, 0x00, 0x6B);
                case 8:
                    return Color.FromArgb(0xFF, 0x80, 0xDF);
                case 9:
                    return Color.FromArgb(0x60, 0x78, 0xBF);
                default:
                    return Color.FromArgb(0xCF, 0xE6, 0xCF);
            }
        }

        public static Color GetLineColor(int index)
        {
            index = index % 10;
            switch (index)
            {
                case 0:
                    return Color.Yellow;
                case 1:
                    return Color.FromArgb(0x00, 0x99, 0x99);
                case 2:
                    return Color.FromArgb(0x66, 0x00, 0x99);
                case 3:
                    return Color.FromArgb(0xFF, 0x99, 0x00);
                case 4:
                    return Color.FromArgb(0xFF, 0xCC, 0x80);
                case 5:
                    return Color.FromArgb(0xFF, 0xFF, 0x00);
                case 6:
                    return Color.FromArgb(0xFF, 0x00, 0x00);
                case 7:
                    return Color.FromArgb(0xCC, 0x00, 0x99);
                case 8:
                    return Color.FromArgb(0xFF, 0xBF, 0xEF);
                case 9:
                    return Color.FromArgb(0xBF, 0xCF, 0xEF);
                default:
                    return Color.FromArgb(0x5C, 0xB8, 0x5C);
            }
        }

        public static void SetCommonLineItemStyle(LineItem lineItem)
        {
            lineItem.Line.IsAntiAlias = true;
            lineItem.Line.Width = 2.0F;
            lineItem.Line.Color = Color.Yellow;
            lineItem.Symbol.IsAntiAlias = true;

            lineItem.Symbol.Size = 8.0F;
            lineItem.Symbol.Fill = new Fill(Color.Red);
            lineItem.Symbol.Type = SymbolType.Circle;            
        }

        public static void SetGrowthGridCols(DataGridView dgv, string analyseTimeType, GuideLineType type)
        {
            dgv.Columns[0].HeaderText = analyseTimeType;
            dgv.Columns[1].HeaderText = type.GetFullName();
        }

        public static void SetGrowthGridStyle(DataGridView dgv)
        {
            dgv.AllowUserToAddRows = false;
            dgv.AllowUserToDeleteRows = false;
            dgv.AllowUserToResizeColumns = false;
            dgv.AllowUserToResizeRows = false;
            dgv.BackgroundColor = System.Drawing.Color.Black;
            dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;

            DataGridViewCellStyle headerCellstyle = new DataGridViewCellStyle();
            headerCellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            headerCellstyle.BackColor = System.Drawing.Color.Black;
            headerCellstyle.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            headerCellstyle.ForeColor = System.Drawing.Color.Aquamarine;
            headerCellstyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            headerCellstyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            headerCellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            dgv.ColumnHeadersDefaultCellStyle = headerCellstyle;
            dgv.ColumnHeadersHeight = 35;
            dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

            DataGridViewCellStyle defaultCellstyle = new DataGridViewCellStyle();
            defaultCellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            defaultCellstyle.BackColor = System.Drawing.Color.Black;
            defaultCellstyle.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            defaultCellstyle.ForeColor = System.Drawing.Color.Yellow;
            defaultCellstyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            defaultCellstyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            defaultCellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
            dgv.DefaultCellStyle = defaultCellstyle;

            dgv.EnableHeadersVisualStyles = false;
            dgv.GridColor = System.Drawing.Color.Gainsboro;
            dgv.ReadOnly = true;
            dgv.RowHeadersVisible = false;
            dgv.RowHeadersWidth = 4;
            dgv.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgv.RowTemplate.Height = 23;
            dgv.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;

            // 
            // Column1
            // 
            DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
            col1.DataPropertyName = "Period";
            DataGridViewCellStyle col1Cellstyle = new DataGridViewCellStyle();
            col1Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            col1Cellstyle.ForeColor = System.Drawing.Color.DeepSkyBlue;
            col1Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col1.DefaultCellStyle = col1Cellstyle;
            col1.HeaderText = "期";
            col1.Name = "Column1";
            col1.ReadOnly = true;
            col1.Width = 60;
            // 
            // Column2
            // 
            DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
            col2.DataPropertyName = "GuideLineValue";
            DataGridViewCellStyle col2Cellstyle = new DataGridViewCellStyle();
            col2Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            col2Cellstyle.ForeColor = System.Drawing.Color.Yellow;
            col2Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col2.DefaultCellStyle = col2Cellstyle;
            col2.HeaderText = "货币资金";
            col2.Name = "Column2";
            col2.ReadOnly = true;
            col2.Width = 120;
            // 
            // Column3
            // 
            DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();
            col3.DataPropertyName = "GrowthRate";
            DataGridViewCellStyle col3Cellstyle = new DataGridViewCellStyle();
            col3Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            col3Cellstyle.ForeColor = System.Drawing.Color.Yellow;
            col3Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col3.DefaultCellStyle = col3Cellstyle;
            col3.HeaderText = "增长率";
            col3.Name = "Column3";
            col3.ReadOnly = true;
            col3.Width = 80;
            // 
            // Column4
            // 
            DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();
            col4.DataPropertyName = "CompoundGrowthRate";
            DataGridViewCellStyle col4Cellstyle = new DataGridViewCellStyle();
            col4Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            col4Cellstyle.ForeColor = System.Drawing.Color.Yellow;
            col4Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col4.DefaultCellStyle = col4Cellstyle;
            col4.HeaderText = "复合增长率";
            col4.Name = "Column4";
            col4.ReadOnly = true;
            col4.Width = 80;
            // 


            dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            col1,
            col2,
            col3,
            col4});
        }
    }
}
